package cn.edu.suda.vote.util;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import java.util.List;

import cn.edu.suda.vote.bean.VoteInfo;
import cn.edu.suda.vote.vote.R;

/**
 * Created by gzy on 2016/5/27.
 */
public class MyAdapter extends BaseAdapter {

    private Context context;
    private List<VoteInfo> voteInfos;

    public MyAdapter(Context context, List<VoteInfo> voteInfos) {
        this.context = context;
        this.voteInfos = voteInfos;
    }

    @Override
    public int getCount() {
        return (voteInfos == null) ? 0 : voteInfos.size();
    }

    @Override
    public Object getItem(int position) {
        return voteInfos.get(position);
    }

    @Override
    public long getItemId(int position) {
        VoteInfo voteInfo = (VoteInfo) getItem(position);
        return voteInfo.getViId();
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        VoteInfo voteInfo = (VoteInfo) getItem(position);

        convertView = LayoutInflater.from(context).inflate(R.layout.list_view_item, null);

        ((TextView) convertView.findViewById(R.id.vName_textView)).setText(voteInfo.getVoter().getvName());
        ((TextView) convertView.findViewById(R.id.vScore_textView)).setText(String.valueOf(voteInfo.getViScore()));


        return convertView;
    }
}
